Skip to content

feat: Add optimizely attribute fetching functionality#20

Merged
alexs-mparticle merged 7 commits intodevelopmentfrom
feat/EXP-4851
Apr 8, 2025
Merged

feat: Add optimizely attribute fetching functionality#20
alexs-mparticle merged 7 commits intodevelopmentfrom
feat/EXP-4851

Conversation

@patrick-wu
Copy link
Collaborator

Add Optimizely attribute-fetching function to Kit, invoke right before selectPlacement() calls

Summary

{provide a thorough description of the changes}

Testing Plan

{explain how this has been tested, and what additional testing should be done}

@patrick-wu patrick-wu changed the base branch from main to development April 7, 2025 15:49
@patrick-wu patrick-wu marked this pull request as ready for review April 7, 2025 15:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/Rokt-Kit.js:209

  • Review the condition using a logical OR; verify that using || is intentional and that the behavior when only window.optimizely is truthy meets the intended logic.
if (forwarders.length > 0 || window.optimizely) {

src/Rokt-Kit.js:224

  • Add a safeguard to ensure that optimizelyState.getVariationMap()[expId] is defined before accessing its .id property to prevent potential runtime errors.
acc['rokt.custom.optimizely.experiment.' + expId + '.variationId'] = optimizelyState.getVariationMap()[expId].id;

Copy link
Collaborator

@alexs-mparticle alexs-mparticle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @patrick-wu! Appreciate you rebasing and resubmitting. So far I only have some minor nits but his looks good.

src/Rokt-Kit.js Outdated
});

try {
if (forwarders.length > 0 || window.optimizely) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think logical AND would be more appropriate, right?

Suggested change
if (forwarders.length > 0 || window.optimizely) {
if (forwarders.length > 0 && window.optimizely) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but what about the case where the optimizely sdk wasn't loaded via the kit setup, since the client can still load it directly?

mparticle doc on optimizely integration

While allowing mParticle to automatic load Optimizely reduces the amount of code you need to write, you may choose to initialize Optimizely yourself to prevent “page flashing” in the case where an Optimizely experiment is expected to alter the UI immediately on load. You can read more about this concern here and make the choice that’s best for your setup.

i guess even if they load it themselves, we'd still have a forwarder?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forwarder would still exist yes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok got it. in that case yeah, i'll modify this to &&

try {
if (forwarders.length > 0 || window.optimizely) {
// Get the state object
var optimizelyState = window.optimizely.get('state');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should add some handlers in case optimizelyState returns undefined.

this.selectPlacements = selectPlacements;

// mParticle Kit Callback Methods
function fetchOptimizely() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have a testing framework, I would like to see some tests around this logic. I can help you with mocking if you need it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexs-mparticle can you take a look if these test cases are sufficient?

var selectPlacementsAttributes = mergeObjects(filteredAttributes, {
mpid: mpid,
});
var optimizelyAttributes =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the dist files from the commit. These are built by the CI/CD process.

getVariationMap: function () {
return {};
},
// Missing getActiveExperimentIds
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Updating comment for clarity

Suggested change
// Missing getActiveExperimentIds
// Mocking a scenario for when getActiveExperimentIds() method is missing

@alexs-mparticle alexs-mparticle changed the title Feat: Add optimizely attribute fetching functionality feat: Add optimizely attribute fetching functionality Apr 8, 2025
@alexs-mparticle alexs-mparticle merged commit 198d136 into development Apr 8, 2025
4 checks passed
github-actions bot pushed a commit that referenced this pull request Apr 8, 2025
# [1.2.0](v1.1.0...v1.2.0) (2025-04-08)

### Features

* Add optimizely attribute fetching functionality ([#20](#20)) ([fdf9ca9](fdf9ca9))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants